#!/bin/bash
if [ -z "$M2_REPO" ]
then
	echo "\$M2_REPO not defined."
	exit
fi

mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file -Dfile=artifacts/script-maven-plugin-1.2.0-SNAPSHOT.jar -DpomFile=artifacts/pom.xml -Dsources=artifacts/script-maven-plugin-1.2.0-SNAPSHOT-sources.jar -Djavadoc=artifacts/script-maven-plugin-1.2.0-SNAPSHOT-javadoc.jar

if [ -e $M2_REPO/gap/maven/maven-metadata-local.xml ] 
then
	mkdir transform
	cp $M2_REPO/gap/maven/maven-metadata-local.xml transform/maven-metadata-local-prefix.xml
	mvn xml:transform
	cp transform/merged/maven-metadata-local-prefix.xml $M2_REPO/gap/maven/maven-metadata-local.xml
	rm -R transform
else
	cp artifacts/maven-metadata-local.xml $M2_REPO/gap/maven/maven-metadata-local.xml
fi

# transforming the latest tag for maven 2
mkdir transform
cp $M2_REPO/gap/maven/script-maven-plugin/maven-metadata-local.xml transform/maven-metadata-local-latest.xml
mvn xml:transform
cp transform/merged/maven-metadata-local-latest.xml $M2_REPO/gap/maven/script-maven-plugin/maven-metadata-local.xml
rm -R transform

